package cn._51doit.flink.day01.sources;

import org.apache.flink.api.java.io.TextInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.FileProcessingMode;

/**
 * Source是用来指定以后从哪里读取数据的
 *
 * readTextFile返回的DataStream是一个有限的数据流，数据处理完后，程序退出
 *
 */
public class FileSource2 {

    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        String filePath = "/Users/start/Desktop/a.txt";

        TextInputFormat inputFormat = new TextInputFormat(new Path(filePath));

        DataStreamSource<String> lines = env.readFile(inputFormat, filePath, FileProcessingMode.PROCESS_CONTINUOUSLY, 1000);

        lines.print();

        env.execute();


    }
}
